//
//  UITableView+Additions.h
//  LinHuaQianBusiness
//
//  Created by zhangsong on 16/8/16.
//  Copyright © 2016年 Shuang Qian Online Payment Company. All rights reserved.
//

#import "UITableView+Additions.h"

@implementation  UITableView (SYYTableView)
 
/* xib调用方法 */
- (UITableViewCell *)getCellWithCellXibName:(NSString *)string
{
    if (string.length == 0 || string == nil) {
        string = @"UITABLEVIEWCELL";
    }
    return [self getCellWithCellXibName:string block:nil];
}

- (UITableViewCell *)getCellWithCellXibName:(NSString *)string block:(void (^)(UITableViewCell *))block
{
    self.separatorStyle = UITableViewCellSeparatorStyleNone;
    id cell = (UITableViewCell*)[self dequeueReusableCellWithIdentifier:string];
    if (cell == nil)
    {
        if ([[string uppercaseString] isEqualToString:@"UITABLEVIEWCELL"])
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:string] ;
            if (block) block(cell);
        }
        else
        {
            NSArray* nibs = [[NSBundle mainBundle] loadNibNamed:string owner:self options:nil];
            for (id oneObject in nibs)
            {
                if ([oneObject isKindOfClass:NSClassFromString(string)])
                {
                    cell = oneObject;
                }
            }
            
        }
    }
    return cell;
}


/* 纯代码调用方法 */
- (UITableViewCell *)getCellWithCellClassName:(NSString *)string
{
    if (string.length == 0 || string == nil) {
        string = @"UITABLEVIEWCELL";
    }
    return [self getCellWithCellClassName:string block:nil];
    
}

- (UITableViewCell *)getCellWithCellClassName:(NSString *)string block:(void (^)(UITableViewCell *))block
{
    self.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    id cell = (UITableViewCell*)[self dequeueReusableCellWithIdentifier:string];
    if (cell == nil)
    {
        if ([[string uppercaseString] isEqualToString:@"UITABLEVIEWCELL"])
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:string] ;
            if (block) block(cell);
        }
        else
        {
            Class MKCell = NSClassFromString(string);
            cell = (UITableViewCell *)[[MKCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:string];


        }
    }
    return cell;
}
- (void)setExtraCellLineHidden
{
    UIView *view =[ [UIView alloc]init];
    view.backgroundColor = [UIColor clearColor];
    [self setTableFooterView:view];
}

-(void)removeNoDataView
{
    for (UIView *subView in self.subviews) {
        if ([subView isKindOfClass:[JYNoDataView class]]) {
            [subView removeFromSuperview];
        }
        
    }
}
@end
